package com.mall.service;

import java.util.Random;

import javax.annotation.PostConstruct;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;

public class BaseService extends SqlSessionDaoSupport {

	@Autowired
	private SqlSessionFactory sqlSessionFactory;

	@PostConstruct
	public void setSqlSessionFactory() {
		super.setSqlSessionFactory(sqlSessionFactory);
	}

	protected static int random(int max, int min) {
		Random random = new Random();
		int s = random.nextInt(max) % (max - min + 1) + min;
		return s;
	}

	protected String joinArray(Object[] objs) {
		if (this.isEmpty(objs)) {
			return "";
		}

		StringBuffer sb = new StringBuffer();
		for (Object obj : objs) {
			sb.append(obj.toString());
		}

		return sb.toString();
	}

	protected boolean isEmpty(Object[] objs) {

		if (objs == null) {
			return true;
		}

		if (objs.length == 0) {
			return true;
		}

		return false;
	}

	protected boolean isNull(Object value) {
		return value == null;
	}

}
